package org.example.sm2;

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.nio.charset.StandardCharsets;

public class JCEInstallTests {
    public static final String text = "test";

    public static void main(String[] args) throws Exception{
        System.out.print("attempting to get a blowfish key...");
        KeyGenerator keyGenerator = KeyGenerator.getInstance("Blowfish");
        keyGenerator.init(128);
        SecretKey key = keyGenerator.generateKey();
        System.out.println("ok");

        System.out.println("encrypt...");
        Cipher cipher = Cipher.getInstance("Blowfish/ECB/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, key);
        byte[] cipherText = cipher.doFinal(text.getBytes(StandardCharsets.UTF_8));

        System.out.println("OK");

        System.out.println("测试成功");
    }
}
